<?php
class UnitTestCase_OAuth_Request extends UnitTestCase {

    public function setUp() {
    
        // set up env
    
    }
    
    public function tearDown() {
    
        // tear down the tests
    
    }
    
    public function testConstructorCanAcceptZeroParameters() {
    
        $request = new OAuth_Request();
        $this->assertIsA($request, 'OAuth_Request');
    
    }
    
    public function testSetRequestUri() {
    
        $request = new OAuth_Request('http://example.com/');
        $this->assertEqual($request->getRequestUri(), OAuth_Uri::factory('http://example.com/'));
        
        $request = new OAuth_Request();
        $request->setRequestUri('http://www.example.com/');
        $this->assertEqual($request->getRequestUri(), OAuth_Uri::factory('http://www.example.com/'));
    
    }
    
    public function testSetRequestMethod() {
    
        $request = new OAuth_Request('http://example.com/', 'POST');
        $this->assertEqual($request->getRequestMethod(), 'POST');
        
        $request = new OAuth_Request();
        $request->setRequestMethod('GET');
        $this->assertEqual($request->getRequestMethod(), 'GET');
    
    }
    
    public function testRequestMethodDefaultsToPost() {
    
        $request = new OAuth_Request('http://example.com/');
        $this->assertEqual($request->getRequestMethod(), 'POST');
    
    }
    
    public function testQueryParams() {
    
        $request = new OAuth_Request('http://www.example.com/');
        $request->setQueryParam('foo', 'bar');
        $this->assertEqual($request->getQueryParam('foo'), 'bar');
    
    }
    
    public function testPostParams() {
    
        $request = new OAuth_Request('http://www.example.com/');
        $request->setPostParam('foo', 'bar');
        $this->assertEqual($request->getPostParam('foo'), 'bar');
    
    }
    
    public function testSetHeaders() {
    
        $request = new OAuth_Request('http://www.example.com/');
        $request->setHeader('foo', 'bar');
    
    }
    
    public function testSetHeadersOverwritesPrevious() {
    
        $request = new OAuth_Request();
        $request->setHeader('foo', 'bar');
        $this->assertEqual($request->getHeader('foo'), 'bar');
        $request->setHeader('foo', 'bizzle');
        $this->assertEqual($request->getHeader('foo'), 'bizzle');
    
    }
    
	public function testHasHeader() {
	
		$request = new OAuth_Request;
		$this->assertFalse($request->hasHeader('foo'));
		$request->setHeader('foo', 'bar');
		$this->assertTrue($request->hasHeader('foo'));
	
	}
	
	public function testHeaderNamesGetNormalized() {
	
		$request = new OAuth_Request();
		$request->setHeader(' x-FoO  ', 'bar');
		$this->assertEqual($request->getHeader('x-foo'), 'bar');
	
	}
	
	public function testHeaderValuesGetCleaned() {
	
		$request = new OAuth_Request;
		$request->setHeader('foo', "\nBar\n  ");
		$this->assertEqual($request->getHeader('foo'), 'Bar');
	
	}
	
    /*public function testAddHeaderCombinesWithPrevious() {
    
        $request = new OAuth_Request();
        $request->setHeader('foo', 'bar');
        $this->assertEqual($request->getHeader('foo'), 'bar');
        $request->addHeader('foo', 'bizzle');
        $this->assertEqual($request->getHeader('foo'), 'bar,bizzle');
    
    }*/
	
	public function testSetHeaderUsingArray() {
	
		// coming soon!
	
	}
	
    public function xtestSomething() {
    
        $request = new OAuth_Request('http://www.example.com/');
        $request->setParam('page', 'foo')
            ->setParam('start', 25)
            ->setRawPost('This is some raw post data')
            ->setHeader('user-agent', 'Some agent')
            ->setHeader('accept-encoding', array('x-compress', 'x-zip'))
            ->setHeader('accept', 'text/x-dvi', array('q' => '.8', 'mxt' => '5.0'))
            ->addHeader('accept', array('text/html', 'text/plain'));
        
        $dispatcher = new OAuth_Dispatcher();
        $requestAdapter = new OAuth_Request_Curl();
        $response = $dispatcher->dispatch($request, $requestAdapter);
        print $response; // sends response to the browser...
    
    }

}
